﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.ComponentModel;

namespace Bpms.Control
{
    /// <summary>
    /// The Form class extends the HtmlForm HTML control by overriding its RenderAttributes()
    /// method and NOT emitting an action attribute.
    /// </summary>
    public class Form : System.Web.UI.HtmlControls.HtmlForm
    {
        /// <summary>
        /// The RenderAttributes method adds the attributes to the rendered &lt;form&gt; tag.
        /// We override this method so that the action attribute is not emitted.
        /// </summary>
        protected override void RenderAttributes(HtmlTextWriter writer)
        {
            // write the form's name
            // writer.WriteAttribute("name", this.Name);
            // base.Attributes.Remove("name");

            //// write the form's method
            //writer.WriteAttribute("method", this.Method);
            //base.Attributes.Remove("method");

            //// remove the action attribute
            //base.Attributes.Remove("action");

            //// finally write all other attributes
            // this.Attributes.Render(writer);

            //if (base.ID != null)
            //    writer.WriteAttribute("id", base.ClientID);

            //  base.RenderAttributes(writer);

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            System.IO.StringWriter sw = new System.IO.StringWriter(sb);
            System.Web.UI.Html32TextWriter w = new System.Web.UI.Html32TextWriter(sw);

            base.RenderAttributes(w);

            string html = sb.ToString();

            w.Close();

            int start = html.IndexOf("action=\"") + 8;
            int end = html.IndexOf("\"", start);

            html = html.Remove(start, end - start);

            writer.Write(html);
        }

    }
}
